<template>
  <div class="acount-huazhuan person-bg">
    <div class="transfer radius bd-borderBase flex js-sp align-center mb-20">
      <div class="left flex flex-column js-ar align-center">
        <div class="round bg-2E"></div>
        <div class="small-round bg-EA"></div>
        <div class="small-round bg-EA"></div>
        <div class="small-round bg-EA"></div>
        <div class="round bg-CF"></div>
      </div>
      <div class="hua-center text-left">
        <div class="h-c-half bdb-borderBase flex align-center person-input">
          <span class="persontext-t1 text-12 mr-17 w30 flex-shrink-0">
            {{ $t("exchange.from") }}
          </span>
          <!-- <span
            class="persontext-t2 text-14 ml-17 flex-shrink-0"
            v-if="state.downplace"
          >
            {{ $t("assets.currencyAccount") }}
          </span> -->
          <el-select
            v-model="state.stockAccount"
            @change="changeStockAccount"
            popper-class="popper-dark"
         
            placeholder
          >
          <!-- v-show="
                item.isShow &&
                  item.id !== state.stockChangeAccount &&
                  countShow(item)
              " -->
            <el-option
              v-for="(item,index) in state.acountList"
              :key="item.id"
              :label="item.name"
              :value="item.account_code"
          
            ></el-option>
          </el-select>
          <!-- <el-select
            v-model="state.stockChangeAccount"
            @change="getBalance"
            placeholder
            v-if="!state.downplace"
            popper-class="popper-dark"
          >
            <div>
              <el-option
                v-for="item in state.changeAccountBox"
                :key="item.id"
                :label="item.account"
                :value="item.id"
                v-show="
                  item.isShow &&
                    item.id !== state.stockAccount &&
                    countAccountBoxShow(item)
                "
              ></el-option>
            </div>
          </el-select> -->
        </div>
        <div class="h-c-half flex align-center person-input">
          <span class="persontext-t1 text-12 mr-17 w30">
            {{ $t("exchange.to") }}
          </span>
      
            <el-select
              v-model="state.stockChangeAccount"
              placeholder
              @change="getBalance"
              popper-class="popper-dark"
           
            >

            <!-- v-show="
                    item.is_display &&
                      item.id !== state.stockAccount &&
                      countAccountBoxShow(item)
                  " -->
              <div>
                <el-option
                  v-for="(item,index) in state.changeAccountBox"
                  :key="item.id"
                  :label="item.name"
                  :value="item.account_code"
               
                ></el-option>
              </div>
            </el-select>
            <!-- <div></div> -->
          <!-- <el-select
            v-model="state.stockAccount"
            placeholder
            @change="changeStockAccount"
            v-if="!state.downplace"
            popper-class="popper-dark"
          >
            <el-option
              v-for="item in state.acountList"
              :key="item.id"
              :label="item.account"
              :value="item.id"
              v-show="
                item.isShow &&
                  item.id !== state.stockChangeAccount &&
                  countShow(item)
              "
            ></el-option>
          </el-select> -->
        </div>
      </div>
      <div
        class="hua-right bd-borderBase radius flex js-ct align-center point"
        @click="change"
      >
        <img src="@/assets/images/icon_change_light.png" alt />
      </div>
    </div>
    <div class="mb-20">
      <el-select
        @change="getBalance"
        v-model="state.param.currency_id"
        :placeholder="$t('exchange.selectCurrencyTip')"
        popper-class="popper-dark"
      >
        <el-option
          v-for="item in state.currencyList"
          :key="item.id"
          :label="item.currency_code"
          :value="item.currency_id"
        ></el-option>
      </el-select>
    </div>
    <div class="mb-10">
      <el-input
        :placeholder="$t('exchange.inputTransNum')"
        v-model="state.param.transfer_number"
        @input="transferNumberChange"
        :controls="false"
        placeholder-color="red"
        class="huazhuan-center quotet3"
        type="text"
      />
      <!-- <el-input-number
        v-model="state.param.transfer_number"
        :controls="false"
        :min="1"
        :max="state.balance"
        :placeholder="$t('exchange.inputTransNum')"
      ></el-input-number> -->
    </div>
    <div class="balance flex js-sp mb-30">
      <span class="persontext-t3 text-12"
        >{{ $t("assets.availableBalance") }}:
        {{ $currency(state.balance) }}</span
      >
      <span class="personlink text-12 point" @click="allin">
        {{ $t("exchange.transferAll") }}
      </span>
    </div>
    <div
      class="btn radius login-btn text-16 share-color point text-center"
      v-loading="state.loading"
      @click="submitForm"
    >
      {{ $t("formTip.comfirm") }}
    </div>
  </div>
</template>

<script>
import { onMounted, reactive, computed, watch } from "vue";
import { currencyList } from "@/api/currency";
import { transferInfo, userAssetsTransfer,accountList,account_transfer} from "@/api/assets";
// import { orderCurrencyPairBlance } from "@/api/foreign-exchange";
import { toBeNumber } from "@/utils/common";
import { ElMessage } from "element-plus";
import { useI18n } from "vue-i18n";
import { useStore } from "vuex";
import UseSystemSetting from "@/commonapi/useSystemSetting";

export default {
  props: {
    type: Number,
    currency: Number,
    downplace: Boolean,
    accountType: Number,
  },
  emits: ["close", "getbalance"],
  setup(props, { emit }) {
    const { t } = useI18n();
    // 获取开关状态
    const { default_wallet } = UseSystemSetting();
    const state = reactive({
      curency: [],
      num: "",
      accountBox: [
        //位置下面的账户选择框
        // { id: 1, account: t("assets.fiatAccount") },
        // { id: 31, account: "理财账户" },
        // { id: 2, account: t("assets.contractAccount") },
        // { id: 22, account: t("assets.secondContractAccount") }
      ],
      changeAccountBox: [
        //位置上面的账户选择框
        // { id: 3, account: t("assets.fiatAccount") },
        // { id: 32, account: "理财账户" },
        // { id: 4, account: t("assets.contractAccount") },
        // { id: 23, account: t("assets.secondContractAccount") }
      ],
      allList:[],
      stockAccount:'',//change_account
      stockChangeAccount: '',
      acountList: [],
      stockAcountList: [],
      stockChangeAcountList: [], //选择为股票现货账户不是币币账户时另一个列表
      downplace: true, //选择框位置是否为下 true下 false上
      param: {
        transfer_type:
          props.type === 0
            ? default_wallet.value == 1
              ? 2
              : default_wallet.value == 2
              ? 70001
              : default_wallet.value == 3
              ? 2022
              : 2
            : props.type,
      },
      currencyList: [],
      balance: "-", //账户余额
      loading: false,
    });
    const $store = useStore();
    const systemInfo = computed(() => {
      return $store.state.user.systemInfo;
    });
    const countShow = (val) => {
      if (
        state.stockAccount == 2 ||
        state.stockAccount == 1 ||
        state.stockAccount == 7 ||
        state.stockChangeAccount == 8 ||
        state.stockChangeAccount == 9 ||
        state.stockChangeAccount == 7
      ) {
        if (
          (state.stockAccount == 2 ||
            state.stockAccount == 1 ||
            state.stockAccount == 7) &&
          (state.stockChangeAccount == 1 || state.stockChangeAccount == 2)
        ) {
          return true;
        }
        if (state.stockAccount == 1 || state.stockAccount == 2) {
          if (
            state.stockChangeAccount == 3 ||
            state.stockChangeAccount == 4 ||
            state.stockChangeAccount == 5 ||
            state.stockChangeAccount == 6 ||
            state.stockChangeAccount == 10
          ) {
            if (val.id == 1 || val.id == 2) {
              return true;
            }
          }
        }
        if (
          state.stockAccount == 1 ||
          state.stockAccount == 2 ||
          state.stockAccount == 7
        ) {
          if (state.stockChangeAccount == 8 || state.stockChangeAccount == 9) {
            if (val.id == 1 || val.id == 2 || val.id == 7) {
              return true;
            }
          }
        }
        if (state.stockChangeAccount == 7) {
          if (val.id == 1 || val.id == 8 || val.id == 9 || val.id == 2) {
            return true;
          }
        }
      } else {
        return true;
      }
      return false;
    };
    const countAccountBoxShow = (val) => {
      if (
        state.stockChangeAccount == 2 ||
        state.stockChangeAccount == 1 ||
        state.stockChangeAccount == 7 ||
        state.stockChangeAccount == 8 ||
        state.stockChangeAccount == 9
      ) {
        if (state.stockAccount == 2 || state.stockAccount == 1) {
          return true;
        }
        if (state.stockChangeAccount == 1 || state.stockChangeAccount == 2) {
          if (
            state.stockAccount == 3 ||
            state.stockAccount == 4 ||
            state.stockAccount == 5 ||
            state.stockAccount == 6 ||
            state.stockAccount == 10
          ) {
            if (val.id == 1 || val.id == 2) {
              return true;
            }
          }
        }
        if (
          state.stockChangeAccount == 1 ||
          state.stockChangeAccount == 2 ||
          state.stockChangeAccount == 7
        ) {
          if (state.stockAccount == 8 || state.stockAccount == 9) {
            if (val.id == 1 || val.id == 2 || val.id == 7) {
              return true;
            }
          }
        }

        if (state.stockAccount == 7) {
          if (val.id == 1 || val.id == 8 || val.id == 9 || val.id == 2) {
            return true;
          }
        }
      } else {
        return true;
      }
      return false;
    };
    /**
     * methods
     */
    onMounted(() => {
      console.log("stockAccount", state.stockAccount);
      state.param.transfer_type = nowActive.value;

      if (default_wallet.value == 3 && props.type == 0) {
        state.downplace = false;
      } else {
        state.downplace = props.downplace;
      }
      countUpDown(nowActive.value);
      console.log("props", state.downplace, props.type, typeof props.type);
      getcurrency();
      isShow();
      if (props.currency) {
        state.param.currency_id = props.currency;
        getBalance();
      }
    });
    watch(
      () => state.param.transfer_type,
      (newValue) => {
        if (newValue) {
          // countUpDown(newValue);
          getcurrency();
        }
      }
    );
    watch(
      () => props.currency,
      (newValue) => {
        if (newValue) {
          state.param.currency_id = newValue;
          getBalance();
        }
      }
    );
    watch(
      () =>  state.stockAccount,
      (newValue) => {
        if (newValue) {
              //变化了---
              console.log(state.stockAccount,'还是变化了---state.stockAccount')
                      state.changeAccountBox = computed(() => {
                  return state.allList.filter((item) => {
                    // Filter out the selected to account
                    return item.account_code !== state.stockAccount;
                  });
                })
     
        console.log(state.stockAccount,'变化了---state.stockAccount')
        console.log(state.changeAccountBox,'变化了---111')
        getcurrency()
      
        }
      }
    );

    watch(
      () =>  state.stockChangeAccount,
      (newValue) => {
        if (newValue) {
              console.log('变化了---222')
          state.acountList = computed(() => {
          return state.allList.filter((item) => {
            // Filter out the selected to account
            return item.account_code !== state.stockChangeAccount;
          });
        })
        getcurrency()

        
        }
      }
    );
   
   
    // 判断显隐
    // （1-法币，2-币币，3-合约，4-秒合约,5-理财，6-NFT,7-股票现货,8-股票合约，9-股票秒合约，10-外汇，11-模拟外汇）
    const isShow = () => {
      accountList().then(res=>{
         
         state.allList=res.data;
         state.acountList=res.data;
         state.changeAccountBox=res.data;
         console.log(state.allList,'交换列表')

        //  state.acountList = computed(() => {
        //   return state.allList.filter((item) => {
        //     // Filter out the selected to account
        //     return item.account_code !== state.allList[state.stockAccount].account_code;
        //   });
        // });
      //   console.log(state.acountList,'交换列表1111')

      //   state.changeAccountBox= computed(() => {
      //     return state.allList.filter((item) => {
      //       // Filter out the selected from account
      //       return item.account_code !== state.allList[state.stockChangeAccount].account_code;
      //     });
      // });
      // console.log(state.changeAccountBox,'交换列表1111')
         // state.acountList.push({
         //   id: 1,
         //   account: t("assets.fiatAccount"),
         //   isShow: ele.value,
         // });
   

    
     })
      // systemInfo.value?.forEach((ele) => {
      //   if (ele.key === "wallet_legal") {
      //     state.wallet_legal = ele.value;

          

      //     state.acountList.push({
      //       id: 1,
      //       account: t("assets.fiatAccount"),
      //       isShow: ele.value,
      //     });
      //     state.acountList.push({
      //       id: 2,
      //       account: t("assets.currencyAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 1,
      //       account: t("assets.fiatAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 2,
      //       account: t("assets.currencyAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_lever") {
      //     state.wallet_lever = ele.value;

      //     state.acountList.push({
      //       id: 3,
      //       account: t("assets.contractAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 3,
      //       account: t("assets.contractAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_second_lever") {
      //     state.wallet_second_lever = ele.value;

      //     state.acountList.push({
      //       id: 4,
      //       account: t("assets.secondContractAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 4,
      //       account: t("assets.secondContractAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_project") {
      //     state.wallet_project = ele.value;
      //     state.acountList.push({
      //       id: 5,
      //       account: t("assets.financialAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 5,
      //       account: t("assets.financialAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_forex") {
      //     state.wallet_forex = ele.value;
      //     state.acountList.push({
      //       id: 10,
      //       account: t("foreign.forexAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 10,
      //       account: t("foreign.forexAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_nft") {
      //     state.wallet_nft = ele.value;

      //     state.acountList.push({
      //       id: 6,
      //       account: t("NFT.NFTAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 6,
      //       account: t("NFT.NFTAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_stock") {
      //     state.wallet_stock = ele.value;

      //     state.acountList.push({
      //       id: 7,
      //       account: t("stock.stockNowAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 7,
      //       account: t("stock.stockNowAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_stock_lever") {
      //     state.wallet_stock_lever = ele.value;
      //     state.acountList.push({
      //       id: 8,
      //       account: t("stock.stockLeverAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 8,
      //       account: t("stock.stockLeverAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      //   if (ele.key === "wallet_stock_second_lever") {
      //     state.wallet_stock_second_lever = ele.value;

      //     state.acountList.push({
      //       id: 9,
      //       account: t("stock.stockSecondAccount"),
      //       isShow: ele.value,
      //     });
      //     state.changeAccountBox.push({
      //       id: 9,
      //       account: t("stock.stockSecondAccount"),
      //       isShow: ele.value,
      //     });
      //   }
      // });
    };
    const nowActive = computed(() => {
      if (default_wallet.value) {
        if (default_wallet.value == 1) {
          if (props.type === 0) {
            return 1;
          } else {
            return props.type;
          }
        } else if (default_wallet.value == 2) {
          switch (props.type) {
            case 0:
              return 3;
            case 1:
              return 3;
            case 2:
              return 70001;
            case 22:
              return 70002;
            case 31:
              return 70007;
            case 53:
              return 70008;
            case 2007:
              return 70003;
            case 2013:
              return 70004;
            case 2015:
              return 70005;
            case 60002:
              return 70006;
            default:
              return 70001;
          }
        } else if (default_wallet.value == 3) {
          if (props.type === 0) {
            return 2008;
          } else if (props.type === 1) {
            return 70011;
          } else {
            if (props.type === 2013 || props.type === 2015) {
              switch (props.type) {
                case 2013:
                  return 2021;
                case 2015:
                  return 2022;
                default:
                  return 2021;
              }
            } else {
              return props.type;
            }
          }
        }
      } else {
        return props.type;
      }
      return props.type;
    });
    //计算transfer_type属性
    const countTransferType = computed(() => {
      if (state.downplace) {
        //币币
        if (state.stockAccount == 2) {
          switch (state.stockChangeAccount) {
            case 1:
              return 1;
            case 3:
              return 2;
            case 4:
              return 22;
            case 5:
              return 31;
            case 6:
              return 53;
            case 7:
              return 2007;
            case 8:
              return 2013;
            case 9:
              return 2015;
            case 10:
              return 60002;
            default:
              return 1;
          }
        } else if (state.stockAccount == 1) {
          //法币
          switch (state.stockChangeAccount) {
            case 2:
              return 3;
            case 3:
              return 70001;
            case 4:
              return 70002;
            case 5:
              return 70007;
            case 6:
              return 70008;
            case 7:
              return 70003;
            case 8:
              return 70004;
            case 9:
              return 70005;
            case 10:
              return 70006;
            default:
              return 3;
          }
        } else if (state.stockAccount == 3) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70009;
            case 2:
              return 4;
            default:
              return 4;
          }
        } else if (state.stockAccount == 4) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70010;
            case 2:
              return 23;
            default:
              return 23;
          }
        } else if (state.stockAccount == 5) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70015;
            case 2:
              return 32;
            default:
              return 32;
          }
        } else if (state.stockAccount == 6) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70016;
            case 2:
              return 54;
            default:
              return 54;
          }
        } else if (state.stockAccount == 7) {
          //法币
          switch (state.stockChangeAccount) {
            case 8:
              return 2021;
            case 9:
              return 2022;
            default:
              return 2021;
          }
        } else if (state.stockAccount == 8) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70012;
            case 2:
              return 2014;
            case 7:
              return 2023;
            default:
              return 2014;
          }
        } else if (state.stockAccount == 9) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70013;
            case 2:
              return 2016;
            case 7:
              return 2024;
            default:
              return 2016;
          }
        } else if (state.stockAccount == 10) {
          //法币
          switch (state.stockChangeAccount) {
            case 1:
              return 70014;
            case 2:
              return 60003;
            default:
              return 60003;
          }
        }
      } else {
        //币币
        if (state.stockChangeAccount == 2) {
          switch (state.stockAccount) {
            case 1:
              return 3;
            case 3:
              return 4;
            case 4:
              return 23;
            case 5:
              return 32;
            case 6:
              return 54;
            case 7:
              return 2008;
            case 8:
              return 2014;
            case 9:
              return 2016;
            case 10:
              return 60003;
            default:
              return 3;
          }
        } else if (state.stockChangeAccount == 1) {
          //法币
          switch (state.stockAccount) {
            case 2:
              return 1;
            case 3:
              return 70009;
            case 4:
              return 70010;
            case 5:
              return 70015;
            case 6:
              return 70016;
            case 7:
              return 70011;
            case 8:
              return 70012;
            case 9:
              return 70013;
            case 10:
              return 70014;
            default:
              return 1;
          }
        } else if (state.stockChangeAccount == 3) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70001;
            case 2:
              return 2;
            default:
              return 2;
          }
        } else if (state.stockChangeAccount == 4) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70002;
            case 2:
              return 22;
            default:
              return 22;
          }
        } else if (state.stockChangeAccount == 5) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70007;
            case 2:
              return 31;
            default:
              return 31;
          }
        } else if (state.stockChangeAccount == 6) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70008;
            case 2:
              return 53;
            default:
              return 53;
          }
        } else if (state.stockChangeAccount == 7) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70003;
            case 2:
              return 2007;
            case 8:
              return 2023;
            case 9:
              return 2024;
            default:
              return 70003;
          }
        } else if (state.stockChangeAccount == 8) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70004;
            case 2:
              return 2013;
            case 7:
              return 2021;
            default:
              return 2013;
          }
        } else if (state.stockChangeAccount == 9) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70005;
            case 2:
              return 2015;
            case 7:
              return 2022;
            default:
              return 2015;
          }
        } else if (state.stockChangeAccount == 10) {
          //法币
          switch (state.stockAccount) {
            case 1:
              return 70006;
            case 2:
              return 60002;
            default:
              return 60002;
          }
        }
      }
      return 1;
    });
    //识别transfer_type转换成上下输入框
    const countUpDown = (val) => {
      // if (
      //   val == 1 ||
      //   val == 2 ||
      //   val == 22 ||
      //   val == 31 ||
      //   val == 53 ||
      //   val == 2007 ||
      //   val == 2013 ||
      //   val == 2015 ||
      //   val == 60002
      // ) {
      //   state.stockAccount = 2;
      //   switch (val) {
      //     case 1:
      //       return (state.stockChangeAccount = 1);
      //     case 2:
      //       return (state.stockChangeAccount = 3);
      //     case 22:
      //       return (state.stockChangeAccount = 4);
      //     case 31:
      //       return (state.stockChangeAccount = 5);
      //     case 53:
      //       return (state.stockChangeAccount = 6);
      //     case 2007:
      //       return (state.stockChangeAccount = 7);
      //     case 2013:
      //       return (state.stockChangeAccount = 8);
      //     case 2015:
      //       return (state.stockChangeAccount = 9);
      //     case 60002:
      //       return (state.stockChangeAccount = 10);
      //     default:
      //       return (state.stockChangeAccount = 1);
      //   }
      // } else if (
      //   val == 3 ||
      //   val == 70001 ||
      //   val == 70002 ||
      //   val == 70003 ||
      //   val == 70004 ||
      //   val == 70005 ||
      //   val == 70006 ||
      //   val == 70007 ||
      //   val == 70008
      // ) {
      //   state.stockAccount = 1;
      //   switch (val) {
      //     case 3:
      //       return (state.stockChangeAccount = 2);
      //     case 70001:
      //       return (state.stockChangeAccount = 3);
      //     case 70002:
      //       return (state.stockChangeAccount = 4);
      //     case 70007:
      //       return (state.stockChangeAccount = 5);
      //     case 70008:
      //       return (state.stockChangeAccount = 6);
      //     case 70003:
      //       return (state.stockChangeAccount = 7);
      //     case 70004:
      //       return (state.stockChangeAccount = 8);
      //     case 70005:
      //       return (state.stockChangeAccount = 9);
      //     case 70006:
      //       return (state.stockChangeAccount = 10);
      //     default:
      //       return (state.stockChangeAccount = 1);
      //   }
      // } else if (val == 2008 || val == 2021 || val == 2022 || val == 70011) {
      //   state.stockAccount = 7;
      //   switch (val) {
      //     case 2008:
      //       return (state.stockChangeAccount = 2);
      //     case 2021:
      //       return (state.stockChangeAccount = 8);
      //     case 2022:
      //       return (state.stockChangeAccount = 9);
      //     case 70011:
      //       return (state.stockChangeAccount = 1);
      //     default:
      //       return (state.stockChangeAccount = 2);
      //   }
      // }
    };
    // 改变划转方向
    const change = () => {
      console.log(state.param.transfer_type);
      let type = state.stockAccount;
      state.stockAccount = state.stockChangeAccount;
      state.stockChangeAccount = type;
      state.downplace = !state.downplace;
      state.param.transfer_type = countTransferType.value;
      console.log(
        state.stockAccount,
        state.stockChangeAccount,
        state.downplace
      );
      getBalance();
      // if (state.param.currency_id) {
      //   getBalance();
      // }
    };
    // 获取法币币种
    const getcurrency = () => {
      let data = {
        currency_legal_status:
          state.param.transfer_type === 32 ||
          state.param.transfer_type === 31 ||
          state.param.transfer_type === 53 ||
          state.param.transfer_type === 60003 ||
          state.param.transfer_type === 54
            ? null
            : true,
      };
      //请先选择货币
      if(state.stockAccount!=''&&state.stockChangeAccount!=''){
       
       let form= state.allList.filter((item) => {
            // Filter out the selected to account
            return item.account_code == state.stockAccount;
          });
          let to=state.allList.filter((item) => {
            // Filter out the selected to account
            return item.account_code == state.stockChangeAccount;
          });
          console.log(form,'form')
          console.log(to,'to')
        let list=form[0]?.accounts?.filter(from => {
          return to[0]?.accounts?.findIndex(to => to.currency_id === from.currency_id) > -1;
        }) || [];
        console.log('匹配到的list',list)
        state.currencyList = list;
      }
      // currencyList(data).then((res) => {
      //   state.currencyList = res.data;
      // });
    };
    // 获取余额信息
    const getBalance = () => {
      console.log(state.stockChangeAccount);
      state.param.transfer_type = countTransferType.value;
      console.log(state.param.transfer_type);
      // if (!state.param.currency_id) {
      //   // 没选择币种
      //   return;
      // }
      let i='';
      state.allList.forEach((item,index)=>{
       
        if(item.account_code==state.stockAccount){
          i=index
          state.balance = item.convert_usd;
        }
      })


      const param = {
        currency_id: state.param.currency_id,
        transfer_type: state.param.transfer_type,
      };
      // transferInfo(param).then((res) => {
      //   state.balance = res.data.balance;
      // });
      // if (state.param.transfer_type != 60003) {

      // } else {
      //   let account_type = props.accountType || 1;
      //   orderCurrencyPairBlance(account_type).then((res) => {
      //     state.balance = res.data.balance;
      //   });
      // }
    };
    //当从币币账户切换成股票现货账户，重置另一个列表和选择类型
    const changeStockAccount = (val) => {
      console.log(
        "transfer_type",
        state.downplace,
        val,
        countTransferType.value
      );
      // state.changeAccountBox = computed(() => {
      //     return state.allList.filter((item) => {
      //       // Filter out the selected to account
      //       return item.account_code !== state.allList[val].account_code;
      //     });
      //   })
        console.log('valzzzzzz',val)
        // console.log('当前的code',state.allList[val].account_code)
        // console.log('另一个值',state.changeAccountBox)
      state.param.transfer_type = countTransferType.value;
      getBalance();
      // if (state.param.currency_id) {
      //   getBalance();
      // }
    };
    // 划转数量变化
    const transferNumberChange = (val) => {
      if (val) {
        let tempV = toBeNumber(val);
        state.param.transfer_number = tempV;
      }
    };
    // 全部划转
    const allin = () => {
      state.param.transfer_number = state.balance;
    };
    // 点击确认
    const submitForm = () => {
      if (!state.param.currency_id) {
        // 未选择币种
        ElMessage.error(t("exchange.selectCurrencyTip"));
        return;
      }
      if (!state.param.transfer_number) {
        // 请选择币种
        ElMessage.error(t("exchange.inputTransNum"));
        return;
      }
      if (state.param.transfer_number > state.balance) {
        // 余额不足
        ElMessage.error(t("lever.balanceinsu"));
        return;
      }
      if (Number(state.param.transfer_number) <= 0) {
        return;
      }
        state.param.balance=state.param.transfer_number
        // state.param.currency_id=
        state.param.from=state.stockAccount
        state.param.to=state.stockChangeAccount
      state.loading = true;
      account_transfer(state.param)
        .then((res) => {
          if (res.code === 1) {
            ElMessage({
              type: "success",
              message: res.msg,
            });
            emit("close");
            emit("getbalance");
            state.loading = false;
          }else{
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {
          state.loading = false;
        });
    };
    return {
      state,
      change,
      getcurrency,
      getBalance,
      allin,
      submitForm,
      transferNumberChange,
      systemInfo,
      isShow,
      changeStockAccount,
      nowActive,
      countShow,
      countAccountBoxShow,
      countTransferType,
      countUpDown,
    };
  },
};
</script>

<style scoped lang="less">
.acount-huazhuan {
  padding: 10px;
  box-sizing: border-box;
}
.transfer {
  width: 100%;
  height: 120px;
  padding: 0 10px 0 7px;
  box-sizing: border-box;
}
.left {
  width: 13px;
  height: 54px;
}
.round {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.small-round {
  width: 4px;
  height: 4px;
  border-radius: 50%;
}
.bg-2E {
  background: @blue;
}
.bg-CF {
  background: #cf2f43;
}
.bg-EA {
  background: #eaecef;
}
.hua-center {
  width: 250px;
  height: 100%;
}
.h-c-half {
  height: 50%;
  width: 100%;
  // line-height: 60px;
}
.mr-17 {
  margin-inline-end: 17px;
}
.ml-17 {
  margin-inline-start: 17px;
}
.hua-right {
  height: 100px;
  width: 60px;
  img {
    width: 19.9px;
    height: 19.9px;
  }
}
.el-input__inner {
  border: 1px solid white;
}
.mb-20 {
  margin-bottom: 20px;
}
.mb-30 {
  margin-bottom: 30px;
}
.mb-10 {
  margin-bottom: 10px;
}
.el-select {
  width: 100%;
}
.el-input-number {
  width: 100%;
}
.balance {
  width: 100%;
}
.btn {
  height: 46px;
  line-height: 46px;
}
.w30 {
  width: 30px;
}
.huazhuan-center > .el-input__inner {
  text-align: center !important;
}
</style>
